#-------------------------------------------------------------------------------
# Name:        Intro
# Purpose:
#
# Author:      Pablo
#
# Created:     29/04/2013
# Copyright:   (c) Monxcleyr Productions 2013
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame

class Intro():

  """class comment"""

  def __init__(self, surface, common, music):
    self.surface = surface
    self.common = common
    self.ocean = pygame.image.load('resources/graphics/sprites/ocean.bmp')
    self.oceanpos = (0, -2600)
    self.ship = pygame.image.load('resources/graphics/sprites/introship.bmp')
    self.ship.set_colorkey((255,0,255))
    self.shippos = (480, 288)
    self.count = 0
    self.fade = pygame.Surface(self.common.initsize)
    self.fade.fill((255,255,255))
    self.fade.set_alpha(0)
    self.alpha = 0
    self.music = music
    self.time = 0
    # 1000

  def run(self, time):

    self.time += time

    if self.music.getCurrentLoop() != 'ocean':
      self.music.loadQueue('ocean')
      self.music.playQueue()
    if pygame.mixer.music.get_busy() == 0:
      self.music.playQueue()

    self.count += 1

    key = pygame.key.get_pressed()

    if key[pygame.K_a]:
      self.shippos = (self.shippos[0] - .5, self.shippos[1])
    if key[pygame.K_d]:
      self.shippos = (self.shippos[0] + .5, self.shippos[1])

    if self.shippos[0] < 10:
      self.shippos = (10, self.shippos[1])
    if self.shippos[0] > (self.surface.get_width() - self.ship.get_width() - 10):
      self.shippos = ((self.surface.get_width() - self.ship.get_width() - 10), self.shippos[1])

    self.oceanpos = (self.oceanpos[0], self.oceanpos[1] + 1)

    self.surface.blit(self.ocean, self.oceanpos)

    self.surface.blit(self.ship, self.shippos)

    if self.time > 7000:

      self.alpha += 2.55
      self.fade.set_alpha(self.alpha)
      self.surface.blit(self.fade, (0,0))
      if self.alpha >= 255:
        return True
